const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo: app.globalData.userInfo,
    setting: app.globalData.setting,
    navHeight: app.globalData.navHeight,
    capsule: app.globalData.capsule,
    mchs: null,
    mch:null,
    showmodal:false
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getMchs()
  },
  getMchs() {
    wx.cloud.callFunction({
      name: 'merchant',
      data: {
        op: 'getMchs',
        status: '0'
      }
    }).then((res) => {
      console.log(res)
      this.setData({
        total:res.result.total,
        mchs: res.result.list
      })
    })
  },
  review(e) {
    let _id = e.currentTarget.dataset._id
    let status = e.currentTarget.dataset.status
    let _openid = e.currentTarget.dataset._openid
    wx.cloud.callFunction({
      name: 'merchant',
      data: {
        op: 'review',
        _id: _id,
        _openid:_openid,
        status:status
      }
    }).then((res) => {
      console.log(res)
      this.modalClose()
      this.getMchs()
    })
  },
  showModal(e){
    let modalName = e.currentTarget.dataset.modalname
    let index = e.currentTarget.dataset.index
    let mchs = this.data.mchs
    this.setData({
      mch:mchs[index],
      showmodal:modalName
    })
  },
  modalClose: function () {
    this.setData({
      showmodal: false
    });
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})